package com.ruipengkj.init;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;

import com.ruipengkj.commons.util.SafeProperties;
public class InitContext {

	
	public static final String url="pool.url";
	public static final String ip="pool.ip";
	public static final String database="pool.database";
	public static final String password="pool.password";
	public static final String username="pool.username";
	

	private static InitContext instance;
	
	private InitContext(){}
	public static InitContext getinstance(){
		if(instance==null){
			instance=new InitContext();
		}
		
		return instance;
	}
	
	
	public Properties LoadFilePath(){
		Properties pros=null;
		try {
			pros=new Properties();
			InputStream is=this.getClass().getResourceAsStream("/filePath.properties");
			pros.load(is);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return pros;
	}
	//获取数据库参数
	public Properties LoadDataBaseData(){
		Properties pros=null;
		try {
			pros=new SafeProperties();
			//InputStream is=this.getClass().getResourceAsStream("/jdbc.properties");
            InputStream is = new FileInputStream("jdbc.properties");
			pros.load(is);
            is.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return pros;
	}
	public void saveDataBaseData(SafeProperties pros){
		try {
//			String path=this.getClass().getResource("/jdbc.properties").getFile();
//			path = URLDecoder.decode(path, "utf-8");
//			OutputStream os=new FileOutputStream(path);
            OutputStream os=new FileOutputStream("jdbc.properties");
			pros.store(os, "jdbc");
            os.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}	
	
	public static void main(String[] args) {
		InitContext.getinstance();
	}	
}
